<!--# layout("/common/layout.html",{"jsBase":"/js/cms/doctoralSubsidy/"}){ -->
<div class="layui-tab" lay-filter="test">
    <ul class="layui-tab-title">
        <li class="layui-this">待办任务</li>
        <li>已办任务</li>

    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <layui:searchFormCheck></layui:searchFormCheck>
            <form class="layui-form ">
                <div class="layui-row">
                    <div class="layui-col-xs4">
                        <div>
                            <div class="layui-card">
                                <div class="layui-card-header">公司</div>
                                <div class="layui-card-body">
                                    <!--#
                                        for(item in companies){
                                        -->
                                    <div class="layui-form-item">
                                        <input type="radio" name="company" title="${item.companyName}(${item.waitCheckNumber}/${item.allCheckNumber})" value="${item.companyId}"
                                               lay-skin="primary" lay-filter="companyRadio">
                                    </div>
                                    <!--# }-->

                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-xs8">
                        <div>
                            <div class="layui-card">
                                <div class="layui-card-header">个人</div>
                                <div class="layui-card-body">
                                    <ul id="employeeList">

                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-tab-item">
            <layui:searchForm formId="searchForm" condition="${search}">
            </layui:searchForm>

            <div class="layui-btn-group">
                <layui:accessButton function="doctoralSubsidy.check" action="find">查看</layui:accessButton>
                <layui:accessButton function="doctoralSubsidy.check" action="process">审核流程</layui:accessButton>

            </div>

            <table id="doctoralSubsidyTable" lay-filter="doctoralSubsidyTable"></table>
        </div>

        <input id="roleName" type="hidden" value="${roleName}">
    </div>
</div>


<!--#} -->
<script>
    function detail(id,bStateCode) {
        layui.use('layer', function () {
            var layer = layui.layer;
            var index = layer.open({
                title: '审核',
                move: false,
                type: 2,
                content: Common.ctxPath +'/cms/doctoralSubsidy/shenhe.do?id='+id+'&roleName=chushen&bStateCode='+bStateCode+''
            });
            layer.full(index);
        });
    }

    /**
     * 公共变量,记录上次触发的companyId
     * 审核后,刷新当前的个人
     * 给子窗口调用
     */
    var shareCompanyId;
    function forChildWindow(){
        helper(shareCompanyId);
    }

    /**
     * 辅助方法
     */
    function helper(companyId){
        var roleName=$("#roleName").val();
        var year= $.trim($("#yearQuery").val());
        var params = {'companyId':companyId,"roleName":roleName,"year":year};
        Common.post("/cms/doctoralSubsidy/employees.json", params, function(data){
            $("#employeeList").html("");
            var content = [];
            var length = data.length;
            for (var index = 0; index < length; index++) {
                var person = data[index];
                if(person.processResult=="初审通过"){
                    content.push("<li onclick='detail(" + person.id + ","+person.businessStateCode+")'>" + person.name + "&nbsp;&nbsp;&nbsp;<img style='width:18px ;height: 20px' src='${ctxPath}/js/1.png'></li>");
                }else if(person.processResult=="初审终止"){
                    content.push("<li onclick='detail(" + person.id + ","+person.businessStateCode+")'>" + person.name + "&nbsp;&nbsp;&nbsp;<img style='width:18px ;height: 20px' src='${ctxPath}/js/2.png'></li>");
                }else if(person.processResult=="初审退回"){
                    content.push("<li onclick='detail(" + person.id + ","+person.businessStateCode+")'>" + person.name + "&nbsp;&nbsp;&nbsp;<img style='width:18px ;height: 20px' src='${ctxPath}/js/3.png'></li>");
                }else if(person.processResult=="企业通过" || person.processResult == "复审退回"
                ){
                    content.push("<li onclick='detail(" + person.id + ","+person.businessStateCode+")'>" + person.name + "&nbsp;&nbsp;&nbsp;<img style='width:18px ;height: 20px' src='${ctxPath}/js/4.png'></li>");
                }
                content.push("<hr class=\"layui-bg-gray\">");
            }
            $("#employeeList").html(content.join(""));

        })
    }

    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'element'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;

        form.on('radio(companyRadio)', function (data) {
            shareCompanyId = data.value;
            helper(shareCompanyId);
        });

        /**
         * 代办任务查询
         */
        form.on('submit(searchForm1)', function(data){
            var index = layer.load(1, {
                shade: [0.5,'#000'] //0.1透明度的背景
            });
            window.location.href = Common.ctxPath + '/cms/doctoralSubsidy/index.do?' + parseParams(data.field);
        });
    });

    layui.use(['element', 'table'], function(){
        var element = layui.element;
        var table = layui.table;
        element.on('tab(test)', function (data) {
            if(data.index ==0) {
                table.reload('doctoralSubsidyTable');
            }
            else if(data.index == 1) {
                table.reload('doctoralSubsidyTable');
            }
        });
    });

    layui.use(['business'], function () {
        var index = layui.business;
        index.init();
    });


</script>
